package org.vectrics.graphics;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.vectrics.SystemException;

/**
 * @author mmoore
 */
public class ImageConfiguration {
	private String id = null;
    private int nextLayerIndex = 0;
    private String name = null;
    private String parentName = null;
    private Integer width = null;
    private Integer height = null;
    private HashMap imageMap = null;
    private String background = null;
    private List layerList = new ArrayList();
    
    /**
     * 
     * @param imageMap - Configuration for all images (used to find parent if parent is referenced).
     */
    public ImageConfiguration(HashMap imageMap) {
        this.imageMap = imageMap;
    }
    
    /**
     * @return Returns the height.
     */
    public Integer getHeight() {
        return height;
    }
    
    /**
     * @param height The height to set.
     */
    public void setHeight(Integer height) {
        this.height = height;
    }
    
    public ImageConfiguration getParent() {
        ImageConfiguration parent = null;
        
        if (this.getParentName() != null) {
            parent = (ImageConfiguration)imageMap.get(this.getParentName());
            if (parent == null)
                throw new SystemException("Could not find image parent: " + this.getParentName());
        }
        return(parent);
    }

    public String getUniqueName() {
    	StringBuffer name = new StringBuffer();
    	name.append(this.getName());
    	return(name.toString());
    }

    /**
     * @return Returns the name.
     */
    public String getName() {
        return name;
    }
    /**
     * @param name The name to set.
     */
    public void setName(String name) {
        this.name = name;
    }
    /**
     * @return Returns the parentName.
     */
    public String getParentName() {
        return parentName;
    }
    /**
     * @param parentName The parentName to set.
     */
    public void setParentName(String parentName) {
        this.parentName = parentName;
    }
    /**
     * @return Returns the width.
     */
    public Integer getWidth() {
        return width;
    }
    /**
     * @param width The width to set.
     */
    public void setWidth(Integer width) {
        this.width = width;
    }
    
    public Integer getPathHeight() {
        Integer pathHeight = null;
        if (this.getHeight() != null)
            pathHeight = this.getHeight();
        else if (this.getParent() != null) {
            pathHeight = getParent().getHeight();
        }
        return(pathHeight);
    }
    
    public Integer getPathWidth() {
        Integer pathWidth = null;
        if (this.getWidth() != null)
            pathWidth = this.getWidth();
        else if (this.getParent() != null) {
            pathWidth = getParent().getWidth();
        }
        return(pathWidth);
    }
    
    public String getPathBackground() {
        String bg = null;
        if (this.getBackground() != null)
            bg = this.getBackground();
        else if (this.getParent() != null)
            bg = this.getParent().getPathBackground();
        return(bg);
    }
    
    
    /**
     * @return Returns the background.
     */
    public String getBackground() {
        return background;
    }
    /**
     * @param background The background to set.
     */
    public void setBackground(String background) {
        this.background = background;
    }
    
    public void addLayer(LayerConfiguration layer) {
        this.layerList.add(layer);
    }
    
    public List getLayerList() {
        return(layerList);
    }
    
    public List getPathLayerList() {
        List pathLayerList = new ArrayList();
        if (this.getParent() != null) {
            pathLayerList.addAll(this.getParent().getPathLayerList());
        }
        pathLayerList.addAll(this.layerList);
        return(pathLayerList);
    }
}
